package com.wenlin.myproduction.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.Nullable;

import com.google.gson.annotations.Expose;
import com.wenlin.myproduction.util.Checker;

import java.io.Serializable;
import java.util.List;

public class NewPlanEn implements Parcelable, Serializable {
    public static final Creator<NewPlanEn> CREATOR = new Creator<NewPlanEn>() {
        @Override
        public NewPlanEn createFromParcel(Parcel in) {
            return new NewPlanEn(in);
        }

        @Override
        public NewPlanEn[] newArray(int size) {
            return new NewPlanEn[size];
        }
    };
    @Expose
    public int StudyPlanId;//计划id
    @Expose
    public int EnLevelId;//等级id
    @Expose
    public String StudyPlanName;//计划名称
    @Expose
    public String ModifyTime;//修改时间
    @Expose
    public String CoverPic;//计划封面
    @Expose
    public int StudyPlanCount;//今天学习计划个数
    @Expose
    public int CanStudyCount; //可读学习计划个数
    @Expose
    public List<NewPlanResEn> ResList;//计划资源列表
    @Expose
    public TeacherEn TeacherInfo;
    @Expose
    public boolean CompleteFlag;//20201117新增，表示该学习计划是否已经完成
    //是否主线计划
    public boolean isTask;//书目共用计划
    //是否检查功能
    public boolean isCheckBook;//校验检查功能可以滑动页面
    //是否已读计划
    public boolean isLocalTask;//是否已读计划
    public List<NewPlanResEn> PageList;//计划资源列表
    public int MustFollowCount;//必须跟读个数


    public NewPlanEn() {

    }

    protected NewPlanEn(Parcel in) {
        StudyPlanId = in.readInt();
        EnLevelId = in.readInt();
        StudyPlanName = in.readString();
        ModifyTime = in.readString();
        CoverPic = in.readString();
        StudyPlanCount = in.readInt();
        CanStudyCount = in.readInt();
        ResList = in.createTypedArrayList(NewPlanResEn.CREATOR);
        TeacherInfo = in.readParcelable(TeacherEn.class.getClassLoader());
        CompleteFlag = in.readByte() != 0;
        isTask = in.readByte() != 0;
        isCheckBook = in.readByte() != 0;
        isLocalTask = in.readByte() != 0;
        PageList = in.createTypedArrayList(NewPlanResEn.CREATOR);
        MustFollowCount = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(StudyPlanId);
        dest.writeInt(EnLevelId);
        dest.writeString(StudyPlanName);
        dest.writeString(ModifyTime);
        dest.writeString(CoverPic);
        dest.writeInt(StudyPlanCount);
        dest.writeInt(CanStudyCount);
        dest.writeTypedList(ResList);
        dest.writeParcelable(TeacherInfo, flags);
        dest.writeByte((byte) (CompleteFlag ? 1 : 0));
        dest.writeByte((byte) (isTask ? 1 : 0));
        dest.writeByte((byte) (isCheckBook ? 1 : 0));
        dest.writeByte((byte) (isLocalTask ? 1 : 0));
        dest.writeTypedList(PageList);
        dest.writeInt(MustFollowCount);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    //简单重写一下equals方法
    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof NewPlanEn) {
            NewPlanEn en = (NewPlanEn) obj;
            //首先id一样，表示是同一个对象。然后名称和封面图一样，老师的信息一样(要么都为空，要么都不为空且各信息都一样），表示基本属性不变。再然后已完成状态不变，表示用户没有新完成计划。
            return this.StudyPlanId == en.StudyPlanId && this.ModifyTime.equals(en.ModifyTime) && this.StudyPlanName.equals(en.StudyPlanName)
                    && (this.TeacherInfo == null && en.TeacherInfo == null || Checker.notNull(this.TeacherInfo) && Checker.notNull(en.TeacherInfo) && this.TeacherInfo.equals(en.TeacherInfo))//在TeacherEn里面已经重写了equals方法，这里直接调用即可
                    && this.CoverPic.equals(en.CoverPic) && this.CompleteFlag == en.CompleteFlag;
        } else {
            return false;
        }
    }
}
